<?php
// start the output buffer
ob_start(); ?>
<?php

require_once 'config.php'; // settings
$INSTALL_PATH = INSTALL_PATH;
$APP_NAME = APP_NAME;

$conn = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS);

		mysql_select_db(MYSQL_DB);		

$query = "SELECT id, url
FROM ".URL_TABLE." 
ORDER BY RAND( )
LIMIT 1";

$result = mysql_query("$query");
while ($r = mysql_fetch_array($result)) {
$id = $r["id"];
$url = $r["url"];
} 

echo "<b>Before:</b> <small><a href=\"$url\">$url</a></small><br><b>After:</b> <small><a href=\"$INSTALL_PATH$id\">$INSTALL_PATH$id</a></small>";

mysql_close($conn); 

?>
<?php
$cachefile = "rand_cache.html";
// open the cache file for writing
$fp = fopen($cachefile, 'w');
// save the contents of output buffer to the file
fwrite($fp, ob_get_contents());
// close the file
fclose($fp);
// Send the output to the browser
ob_end_flush();

?>
